import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
let userInfo = uni.getStorageSync('userInfo') || '';
let userToken = uni.getStorageSync('userToken') || '';
let userMobile = uni.getStorageSync('userMobile') || '';
let configDetail = uni.getStorageSync('configDetail') || '';
let storeInfo = uni.getStorageSync('storeInfo') || '';
let orderInfo = uni.getStorageSync('orderInfo') || '';
let storeCode = uni.getStorageSync('storeCode') || '';
let agreement = uni.getStorageSync('agreement') || '';
let privacy = uni.getStorageSync('privacy') || '';

const store = new Vuex.Store({
	state: {
		userInfo: userInfo,
		userToken: userToken,
		userMobile: userMobile,
		configDetail:configDetail,
		storeInfo: storeInfo,
		orderInfo: orderInfo,
		storeCode: storeCode,
		agreement: agreement,
		privacy: privacy,
	},
	mutations: {
		privacy(state, data) {
			state.privacy = data
			uni.setStorageSync('privacy', data)
		},
		agreement(state, data) {
			state.agreement = data
			uni.setStorageSync('agreement', data)
		},
		storeCode(state, data) {
			// 店铺邀请码
			state.storeCode = data
			uni.setStorageSync('storeCode', data)
		},
		orderInfo(state, data) {
			// 获取店铺详情
			state.orderInfo = data
			uni.setStorageSync('orderInfo', data)
		},
		storeInfo(state, data) {
			// 获取店铺详情
			state.storeInfo = data
			uni.setStorageSync('storeInfo', data)
		},
		configDetail(state, data) {
			// 保存基础配置信息
			state.configDetail = data
			uni.setStorageSync('configDetail', data)
		},
		userInfo(state, data) {
			// 保存用户信息
			state.userInfo = data
			uni.setStorageSync('userInfo', data)
		},
		userToken(state, data) {
			// 保存用户token
			state.userToken = data
			uni.setStorageSync('userToken', data)
		},
		userMobile(state, data) {
			// 保存用户token
			state.userMobile = data
			uni.setStorageSync('userMobile', data)
		},
	}
})

export default store
